package DecorateMode;

/**
 * 装饰者模式
 */

/**
 * 这个例子是：
 * 原本只有照相功能，后续扩展加美颜和滤镜功能
 */
public class DecorateTest {

    public static void main(String[] args) {
        //通过装饰者模式使得一个类具有他不具有的功能
        ConCreateComponent2 conCreateComponent2 = new ConCreateComponent2(new ConCreateComponent1(new ConCreateComponent()));
        conCreateComponent2.operation();
    }
}

interface Component{
    void operation();
}

class ConCreateComponent implements Component{

    @Override
    public void operation() {
        System.out.println("拍照啦");
    }
}

abstract class Decorator implements Component{
    Component component;

    public Decorator(Component component){
        this.component = component;
    }
}

class ConCreateComponent1 extends Decorator {

    public ConCreateComponent1(Component component) {
        super(component);
    }

    @Override
    public void operation() {
        System.out.println("添加美颜啦");
        component.operation();
    }
}

class ConCreateComponent2 extends Decorator {

    public ConCreateComponent2(Component component) {
        super(component);
    }

    @Override
    public void operation() {
        System.out.println("添加滤镜啦");
        component.operation();
    }
}